﻿using HealthcareSystem.API.Read.Application.Command.Followup;
using HealthcareSystem.API.Read.DTO.Element;
using HealthcareSystem.API.Read.DTO.Followup;
using HealthcareSystem.Domain.BasicSettings.FormManagement;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Read.Application.CommandHandel
{
    public class SelectFollowCommandHandel : IRequestHandler<SelectFollowCommand, ApiResult<List<SelectFollowDto>>>
    {
        IBaseRepository<FormCategory> formCategoryHandel;

        public SelectFollowCommandHandel(IBaseRepository<FormCategory> formCategoryHandel)
        {
            this.formCategoryHandel = formCategoryHandel;
        }
        /// <summary>
        /// 表单类型下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<List<SelectFollowDto>>> Handle(SelectFollowCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<SelectFollowDto>> result = new ApiResult<List<SelectFollowDto>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();

            var list = from a in formCategoryHandel.GetAll()
                       select new SelectFollowDto
                       {
                           FormCategoryId = a.FormCategoryId,
                           FormCategoryName = a.FormCategoryName,
                       };

            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
